package com.qst.pojo.vo;

import com.qst.pojo.entity.InventoryHistory;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 库存历史视图对象
 */
@Data
public class InventoryHistoryVO {
    private Integer id;
    private Integer stationId;
    private Integer itemId;
    private String type;  // 操作类型
    private BigDecimal beforeQuantity;
    private BigDecimal changeQuantity;
    private BigDecimal afterQuantity;
    private String reason;
    private String operator;
    private LocalDateTime date;  // 前端期望的字段名
    private String unit;
    
    /**
     * 从InventoryHistory实体转换为VO
     */
    public static InventoryHistoryVO fromEntity(InventoryHistory history) {
        InventoryHistoryVO vo = new InventoryHistoryVO();
        vo.setId(history.getId());
        vo.setStationId(history.getStationId());
        vo.setItemId(history.getItemId());
        vo.setType(history.getOperationType());
        vo.setBeforeQuantity(history.getBeforeQuantity());
        vo.setChangeQuantity(history.getChangeQuantity());
        vo.setAfterQuantity(history.getAfterQuantity());
        vo.setReason(history.getReason());
        vo.setOperator(history.getOperator());
        vo.setDate(history.getCreatedAt());
        
        // 设置物品单位
        if (history.getItem() != null) {
            vo.setUnit(history.getItem().getUnit());
        }
        
        return vo;
    }
}

